package com.wcy.controller.resource;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcy.entity.LearningResource;
import com.wcy.entity.ResourceTag;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.feign.resource.FeignResourceTagService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class ResourceTagController {
    @Resource
    private FeignResourceTagService feignResourceTagService;

    @GetMapping("resourceTag/page")
    public ResponseEntity<PageData<ResourceTag>> getPage(@RequestParam(defaultValue = "1") int pageNum,
                                                         @RequestParam(defaultValue = "10") int pageSize) {
        return ResponseEntity.ok(new PageData<>(ResourceTag.class, Objects.requireNonNull(feignResourceTagService.getPage(pageNum, pageSize).getBody()),  new ApiDescriptor("resourceTag/add", "resourceTag/update", "resourceTag/delete"), ColumnConstructor.create()));
    }

    @GetMapping("resourceTag/list")
    public ResponseEntity<List<ResourceTag>> getList() {
        return feignResourceTagService.getList();
    }

    @PostMapping("resourceTag/add")
    public ResponseEntity<Void> add(@RequestBody ResourceTag resourceTag) {
        return feignResourceTagService.add(resourceTag);
    }

    @PostMapping("resourceTag/update")
    public ResponseEntity<Void> update(@RequestBody ResourceTag resourceTag) {
        return feignResourceTagService.update(resourceTag);
    }

    @PostMapping("resourceTag/delete")
    public ResponseEntity<Void> delete(Integer id) {
        return feignResourceTagService.delete(id);
    }

    @GetMapping("resourceTag/getByResourceId/{id}")
    public ResponseEntity<List<ResourceTag>> getByResourceId(@PathVariable("id") Integer id){
        return feignResourceTagService.getByResourceId(id);
    }
}
